package com.yt.quotes.api.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Config {
	private final static String CONFIG_FILE="config.properties";
	
	private static Config config=null;
	
	private Properties properties;
	
	private Config(){
		initConfig();
	}
	
	private void initConfig() {
		InputStream in=this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE);
		if(properties==null){
			try {
				properties=new Properties();
				properties.load(in);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static Config getInstance(){
		if(config==null){
			config=new Config();
		}
		return config;
	}
	
	public String getProperty(String key){
		if(properties!=null){
			return properties.getProperty(key);
		}
		return null;
	}
	
	public static void main(String[]args){
		System.out.println(Config.getInstance().getProperty("yahoo-quote-data-url"));
	}
}
